﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using unitlControl;
using QLTH_DTO;
using QLTH_BUSINESS;
namespace QuanLy_THPT_S4
{
    public partial class frmPhanLopHS : Form
    {
        private readonly clsPhanLopHSBU plbu;
        private readonly clsPhanLopHSDTO pldto;
        private readonly clsNamHocBU nhbu;
        private readonly clsKhoiBU khbu;
        private readonly clsLopBU lhbu;
        public frmPhanLopHS()
        {
            InitializeComponent();
            plbu = new clsPhanLopHSBU();
            pldto = new clsPhanLopHSDTO();
            nhbu = new clsNamHocBU();
            khbu = new clsKhoiBU();
            lhbu = new clsLopBU();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmPhanLopHS_Load(object sender, EventArgs e)
        {
            radioGroup1.SelectedIndex = 0;
            ComboUtils.SetDataSuorce(cboNamHocCu, nhbu.DanhSachNamHoc(), "MANH", "TENNAMHOC", 0);
            ComboUtils.SetDataSuorce(cboKhoiCu, khbu.DanhSachKhoi(), "MAKHOI", "TENKHOI", 0);
            ComboUtils.SetDataSuorce(cboLopCu, lhbu.DanhSachLop(), "MALOP", "TENLOP", 0);
            gridLopCu.DataSource = plbu.DanhSachHocSinh_ChuaCoLop();

            ComboUtils.SetDataSuorce(cboNamHocMoi, nhbu.DanhSachNamHoc(), "MANH", "TENNAMHOC", 0);
            ComboUtils.SetDataSuorce(cboKhoiMoi, khbu.DanhSachKhoi(), "MAKHOI", "TENKHOI", 0);
            ComboUtils.SetDataSuorce(cboLopMoi, plbu.DanhSachTheo_Khoi_NamHoc(ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi)), "MALOP", "TENLOP", 0);
            gridLopMoi.DataSource = plbu.DanhSachHocSinh_ThuocLopKhoi(ComboUtils.LayGT_Combobox(cboNamHocMoi),ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
       
        
        }

        private void cboNamHocMoi_SelectedValueChanged(object sender, EventArgs e)
        {
            
          ComboUtils.SetDataSuorce(cboLopMoi, plbu.DanhSachTheo_Khoi_NamHoc(ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi)), "MALOP", "TENLOP", 0);
           gridLopMoi.DataSource = plbu.DanhSachHocSinh_ThuocLopKhoi(ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
         //  MessageBox.Show(ComboUtils.LayGT_Combobox(cboLopMoi));
        }

        private void cboKhoiMoi_SelectedValueChanged(object sender, EventArgs e)
        {
            ComboUtils.SetDataSuorce(cboLopMoi, plbu.DanhSachTheo_Khoi_NamHoc(ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi)), "MALOP", "TENLOP", 0);
        }

        private void cboLopMoi_SelectedValueChanged(object sender, EventArgs e)
        {
            gridLopMoi.DataSource = plbu.DanhSachHocSinh_ThuocLopKhoi(ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
        }

        private void cboNamHocCu_SelectedValueChanged(object sender, EventArgs e)
        {
           
            ComboUtils.SetDataSuorce(cboLopCu, plbu.DanhSachTheo_Khoi_NamHoc(ComboUtils.LayGT_Combobox(cboNamHocCu), ComboUtils.LayGT_Combobox(cboKhoiCu)), "MALOP", "TENLOP", 0);
            gridLopCu.DataSource = plbu.DanhSachHS_ConLai(ComboUtils.LayGT_Combobox(cboNamHocCu), ComboUtils.LayGT_Combobox(cboKhoiCu), ComboUtils.LayGT_Combobox(cboLopCu),
                ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));

        }

        private void cboKhoiCu_SelectedValueChanged(object sender, EventArgs e)
        {

            ComboUtils.SetDataSuorce(cboLopCu, plbu.DanhSachTheo_Khoi_NamHoc(ComboUtils.LayGT_Combobox(cboNamHocCu), ComboUtils.LayGT_Combobox(cboKhoiCu)), "MALOP", "TENLOP", 0);
            gridLopCu.DataSource = plbu.DanhSachHS_ConLai(ComboUtils.LayGT_Combobox(cboNamHocCu), ComboUtils.LayGT_Combobox(cboKhoiCu), ComboUtils.LayGT_Combobox(cboLopCu),
             ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
        }

        private void cboLopCu_SelectedValueChanged(object sender, EventArgs e)
        {
            ComboUtils.LayGT_Combobox(cboKhoiCu);
            gridLopCu.DataSource = plbu.DanhSachHS_ConLai(ComboUtils.LayGT_Combobox(cboNamHocCu), ComboUtils.LayGT_Combobox(cboKhoiCu), ComboUtils.LayGT_Combobox(cboLopCu),
            ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
        }

        private void radioGroup1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (radioGroup1.EditValue.ToString() == "1")
            {
                cboNamHocCu.Enabled = false;
                cboKhoiCu.Enabled = false;
                cboLopCu.Enabled = false;
                gridLopCu.DataSource = plbu.DanhSachHocSinh_ChuaCoLop();
            }
            else
            {
                cboNamHocCu.Enabled = true;
                cboKhoiCu.Enabled = true;
                cboLopCu.Enabled = true;
                gridLopCu.DataSource = plbu.DanhSachHS_ConLai(ComboUtils.LayGT_Combobox(cboNamHocCu), ComboUtils.LayGT_Combobox(cboKhoiCu), ComboUtils.LayGT_Combobox(cboLopCu),
            ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
            }
        }

        private void btnPhanlop_Click(object sender, EventArgs e)
        {
            if (radioGroup1.EditValue.ToString() == "1")
            {
                pldto.Lop.Malop = ComboUtils.LayGT_Combobox(cboLopMoi);
                pldto.Mahs = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MAHS").ToString();
                pldto.Siso = "40";
                //  MessageBox.Show(ComboUtils.LayGT_Combobox(cboLopMoi));
                plbu.PhanLop_HS_DauNam(pldto);
                gridLopCu.DataSource = plbu.DanhSachHocSinh_ChuaCoLop();
                gridLopMoi.DataSource = plbu.DanhSachHocSinh_ThuocLopKhoi(ComboUtils.LayGT_Combobox(cboNamHocMoi), 
                    ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
            }
            else 
            {
                pldto.Lop.Malop = ComboUtils.LayGT_Combobox(cboLopMoi);
                pldto.Mahs = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MAHS").ToString();
                pldto.Siso = "40";
              
                plbu.PhanLop_HS_DauNam(pldto);
                gridLopCu.DataSource = plbu.DanhSachHS_ConLai(ComboUtils.LayGT_Combobox(cboNamHocCu),
                    ComboUtils.LayGT_Combobox(cboKhoiCu), ComboUtils.LayGT_Combobox(cboLopCu), 
                    ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), 
                    ComboUtils.LayGT_Combobox(cboLopMoi));
                
                gridLopMoi.DataSource = plbu.DanhSachHocSinh_ThuocLopKhoi(ComboUtils.LayGT_Combobox(cboNamHocMoi),
                    ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
            
            }

        }

        private void btnChuyenve_Click(object sender, EventArgs e)
        {
            if (radioGroup1.EditValue.ToString() == "1")
            {
                pldto.Mahs = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "MAHS").ToString();
                plbu.ChuyenHSVe_DSCu(pldto);
                gridLopCu.DataSource = plbu.DanhSachHocSinh_ChuaCoLop();
                // MessageBox.Show(gridView1.RowCount.ToString());
                gridLopMoi.DataSource = plbu.DanhSachHocSinh_ThuocLopKhoi(ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
            }
            else
            {
                pldto.Mahs = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "MAHS").ToString();
                pldto.Lop.Malop = ComboUtils.LayGT_Combobox(cboLopMoi);
                plbu.XoaHS_LopMoi(pldto);
                gridLopCu.DataSource = plbu.DanhSachHS_ConLai(ComboUtils.LayGT_Combobox(cboNamHocCu), ComboUtils.LayGT_Combobox(cboKhoiCu), ComboUtils.LayGT_Combobox(cboLopCu),
              ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
                gridLopMoi.DataSource = plbu.DanhSachHocSinh_ThuocLopKhoi(ComboUtils.LayGT_Combobox(cboNamHocMoi), ComboUtils.LayGT_Combobox(cboKhoiMoi), ComboUtils.LayGT_Combobox(cboLopMoi));
            }
        }

        private void groupControl1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panelControl3_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
